package utilities;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;

/**
 * Scans a preset group of directories and discovers all files in directories.  Saves full paths plus file names.
 * Returns in a HashMap<filename, filepath>
 * @author RJ
 *
 */
public class AssetFileFinder {
	
	String assetDir;
	char sep = File.separatorChar;
		
	public AssetFileFinder(String rootDir) {
		assetDir = rootDir + sep + "Assets";
	}
	/**
	 * Returns HashMap<filename, filepath (including name)>.  This if full file path, from the drive letter
	 * @return
	 */
	public HashMap<String, String> findAllFiles() {
		File assetFile = new File(assetDir);
		
		//Ignore SVN files (makeSVNaware not working for some reason...)
		IOFileFilter filter = FileFilterUtils.suffixFileFilter("svn-base");
		IOFileFilter notFilter = FileFilterUtils.notFileFilter(filter);
		
		LinkedList<File> files = (LinkedList<File>) FileUtils.listFiles(assetFile, notFilter, TrueFileFilter.INSTANCE); 
//		ArrayList<File> files = (ArrayList<File>) FileUtils.listFiles(assetFile, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
		HashMap<String, String> pathMap = new HashMap<String, String>();		
		String name;
		String path;
		
		for (File file: files) {
			name = file.getName();
			path = file.getPath();
			
			pathMap.put(name, path);
		}
		
		return pathMap;
	}
	

}
